---
sidebar_position: 3
title: Working with Realtime database
sidebar_label: Realtime Database
---

## Available methods

Our Realtime Database adapter provides all the methods the original offers. Due to its nature, we've solved the realtime
listening a bit differently, and thus - this method is not allowed in standard adapter. For the `onValue`-like usage,
please check how to **[listen to queries](/docs/integrations/adapter-firebase/realtime-queries)**.

### get

```tsx
import { firebaseAdapter } from "@hyper-fetch/firebase";

const client = new Client({ url: "teas/" }).setAdapter(() => firebaseAdapter(realtimeDbWeb));
const req = client.createRequest<{ response Tea[] }>()({
  endpoint: "",
  method: "get",
});

const { data, status, extra, success, error } = await req.send();
```

`extra`:

1. `ref` - reference to the endpoint
2. `snapshot` - 'raw' snapshot from the result

### set

```tsx
const setReq = client
  .createRequest<{ response Tea, payload: TeaSchema }>()({
    endpoint: ":teaId",
    method: "set",
  })
  .setParams({ teaId: 1 })
  .setData(newData);

const { data, status, extra, success, error } = await req.send();
```

In case of `set` - data returned is the same data as passed for setting.

`extra`:

1. ref - database reference to the path

You can also **remove data** via set by sending the `{data: null}` object:

```tsx
const setReq = client
  .createRequest<Tea, { data: null }>()({
    endpoint: ":teaId",
    method: "set",
  })
  .setParams({ teaId: 1 })
  .setData({ data: null });
```

### push

```tsx
const pushReq = client
  .createRequest<{ response Tea, payload: TeaSchema }>()({
    endpoint: "",
    method: "push",
    options: {},
  })
  .setData(newData);
```

In case of `push` - data returned is the same data as passed for setting + the `__key` param that equals id of a newly
created document.

`extra`:

1. ref - database reference to the path
2. key - key of the newly created resource

### update

```tsx
const updateReq = client
  .createRequest<{ response Tea, payload: TeaSchema }>()({
    endpoint: ":teaId",
    method: "update",
  })
  .setData(newData);
```

In case of `update` - data returned is the same data as passed for setting.

`extra`:

1. ref - database reference to the path

### remove

```tsx
const removeReq = client
  .createRequest<{ response Tea }>()({
    endpoint: ":teaId",
    method: "remove",
  })
  .setParams({ teaId: 1 });
```

In case of `remove` - returned data equals `null`
